﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
using Demo.Properties;
using System.Text.RegularExpressions;
using System.Configuration;

namespace Demo
{
    static class Program
    {
        /// <summary>
        /// 应用程序的主入口点。
        /// </summary>
        [STAThread]
        static void Main()
        {

            Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
            string html = FillHrefLink("http://www.ibcbet.com", Resources.String2);
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new MiForm());
        }

        public static string FillHrefLink(string website, string html)
        {
            List<string> urls = new List<string>();
            html.GetRegValues("<link .*href=\"(?<BUHUO>.*?)\"", ref urls);
            html.GetRegValues("<script .*src=\"(?<BUHUO>.*?)\"", ref urls);

            foreach (string strUrl in urls)
            {
                if (strUrl.IndexOf('/') == 0)
                    html = html.Replace(strUrl, string.Format("{0}{1}", website, strUrl));
                else
                    html = html.Replace(strUrl, string.Format("{0}/{1}", website, strUrl));
            }
            return html;
        }
        public static void GetRegValues(this string rawString, string regexValue, ref List<string> list)
        {
            Regex regex = new Regex(regexValue, RegexOptions.Multiline | RegexOptions.IgnoreCase);
            MatchCollection matchs = regex.Matches(rawString);
            string strValue = string.Empty;
            for (int i = 0; i < matchs.Count; i++)
            {
                strValue = matchs[i].Groups["BUHUO"].Value;
                if (!string.IsNullOrEmpty(strValue) && !list.Contains(strValue))
                    list.Add(strValue);
            }
        }
    }
}
